using System;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.ViewModel;
using Microsoft.Practices.Unity;
using Ausy.Silverlight.Survey.Infrastructure.Common;
using Ausy.Silverlight.Survey.QuestionModule.Model;

namespace Ausy.Silverlight.Survey.QuestionModule.ViewParts
{
    /// <summary>
    /// Cette classe représente le Vue Model pour le Answer
    /// </summary>
    public class AnswerViewModel : ViewModel<IAnswerView>, IAnswerViewModel
    {
        
        #region Text Property
        /// <summary>
        /// Property text
        /// </summary>
        private string text;

        /// <summary>
        /// Property Text
        /// </summary>
        public string Text
        {
            get { return text; }
            set
            {
                if (text != value)
                {
                    text = value;
                    RaisePropertyChanged(() => this.Text);
                }
            }
        }

        #endregion

        #region CheckedAnswer Property

        /// <summary>
        /// Property checkedAnswer
        /// </summary>
        private bool checkedAnswer;

        /// <summary>
        /// Property CheckedAnswer
        /// </summary>
        public bool CheckedAnswer
        {
            get { return checkedAnswer; }
            set
            {
                if (checkedAnswer != value)
                {
                    checkedAnswer = value;
                    RaisePropertyChanged(() => this.CheckedAnswer);
                }
            }
        }

        #endregion

        #region Answer Property

        /// <summary>
        /// Réponse possible
        /// </summary>
        public Answer Answer { get; private set; }

        #endregion

        #region Constructor

        /// <summary>
        /// Constructeur par défaut
        /// </summary>
        /// <param name="container">Container Unity pour instanciation des type d'objet</param>
        public AnswerViewModel(IUnityContainer container)
            : base(container)
        {

        }

        #endregion

        #region Initialize Method

        /// <summary>
        /// Cette méthode permet l'initialisation du ViewModel avant que le DataContext soit affecté à la vue
        /// </summary>
        protected override void Initialize()
        {
            // Initialisation des données
            this.CheckedAnswer = false;

            // Initialisation des commandes
        }

        #endregion

        #region Load Method

        /// <summary>
        /// Cette méthode permet d'afficher une Réponse
        /// </summary>
        /// <param name="answer">Réponse a afficher</param>
        public void Load(Answer answer)
        {
            if (answer != null)
            {
                this.Answer = answer;
                this.Text = this.Answer.Text;
            }
        }
        #endregion
    }
}
